import axios from 'axios'

const server = axios.create({
    baseURL: process.env.BASE_API,
    timeout: 10000,
    withCredentials: true, // 请求为跨域类型时是否在请求中携带cookie
    method: 'POST', // 默认为post请求
    headers: {
        'Content-Type': 'application/json;charset=utf-8'
    }
})

// 请求拦截器
server.interceptors.request.use(
    config => {
        console.log(config)
        return config
    },
    error => {
        return Promise.reject(error)
    }
)
// 响应拦截器
server.interceptors.response.use(
    response => {
        let res = response.response
        if (res.code === 404) {
            console.log('error')
        }
        return res
    },
    error => {
        return Promise.reject(error)
    }
)

export default server
